home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
mint
/
editors
/
mjovesrc.zoo
/
screen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-04
|
23KB
|
1,083 lines
/***************************************************************************
* This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne. JOVE *
* is provided to you without charge, and with no warranty. You may give *
* away copies of JOVE, including sources, provided that this notice is *
* included in all the files. *
***************************************************************************/
#include "jove.h"
#include "fp.h"
#include "ctype.h"
#include "termcap.h"
#include "disp.h"
#include <signal.h>
int AbortCnt,
tabstop = 8;
bool
CanScroll = NO;
#ifdef TERMCAP
private void
(*TTins_line) proto((int, int, int)),
(*TTdel_line) proto((int, int, int));
#endif /* TERMCAP */
struct scrimage
*DesiredScreen = NULL,
*PhysScreen = NULL;
struct screenline *Screen = NULL, /* the screen (a bunch of screenline) */
*Curline = NULL; /* current line */
private struct screenline *Savelines = NULL; /* another bunch (LI of them) */
private char *cursor; /* offset into current Line */
char *cursend;
int CapCol,
CapLine,
i_line,
i_col;
#ifdef IBMPC
extern unsigned char CHPL;
extern void near normfun(),
near scr_win(),
near clr_page(),
near clr_eoln();
#endif
void
make_scr()
{
register int i;
register struct screenline *ns;
register char *nsp;
/* In case we are RESHAPING the window! */
if (DesiredScreen != NULL)
free((UnivPtr) DesiredScreen);
if (PhysScreen != NULL)
free((UnivPtr) PhysScreen);
if (Savelines != NULL)
free((UnivPtr) Savelines);
if (Screen != NULL) {
free((UnivPtr) Screen->s_line); /* free all the screen data */
free((UnivPtr) Screen);
}
DesiredScreen = (struct scrimage *) malloc((unsigned) LI * sizeof (struct scrimage));
PhysScreen = (struct scrimage *) malloc((unsigned) LI * sizeof (struct scrimage));
Savelines = (struct screenline *)
malloc((unsigned) LI * sizeof(struct screenline));
ns = Screen = (struct screenline *)
malloc((unsigned) LI * sizeof(struct screenline));
nsp = (char *) malloc((unsigned)CO * LI);
if (DesiredScreen == NULL
|| PhysScreen == NULL
|| Savelines == NULL
|| ns == NULL
|| nsp == NULL)
{
writef("\n\rCannot malloc screen!\n");
finish(SIGHUP);
}
for (i = 0; i < LI; i++) {
ns->s_line = nsp;
nsp += CO;
ns->s_length = nsp - 1; /* End of Line */
ns += 1;
}
cl_scr(0);
}
void
clrline(cp1, cp2)
register char *cp1,
*cp2;
{
while (cp1 <= cp2)
*cp1++ = ' ';
}
/* Output one character (if necessary) at the current position */
#ifdef MAC
/* Character output to bit-mapped screen is very expensive. It makes
much more sense to write the entire line at once. So, we print all
the characters, whether already there or not, once the line is
complete. */
private char sput_buf[256];
private int sput_len = 0;
private void
sput_start()
{
/* if (i_line != CapLine || i_col != CapCol) */
NPlacur(i_line, i_col);
sput_len = 0;
}
private void
sput_end()
{
sput_buf[0] = (unsigned char) sput_len;
writechr(sput_buf);
sput_len = 0;
}
private void
sputc(c)
register int c;
{
if (sput_len < sizeof(sput_buf)) {
*cursor++ = c;
sput_buf[++sput_len] = (c == '0')? 0xAF /* slashed zero */ : c;
CapCol++;
i_col++;
}
}
#else /* !MAC */
#ifdef IBMPC
private bool force = NO;
private void
sputc(c)
register int c;
{
if (force || (*cursor != c)) {
if (i_line != CapLine || i_col != CapCol)
Placur(i_line, i_col);
*cursor++ = c;
normfun((char) c);
AbortCnt -= 1;
CapCol += 1;
} else {
cursor += 1;
}
i_col += 1;
}
#else /* !IBMPC */
# define sputc(c) { \
if (*cursor != (char) (c)) { \
do_sputc(c); \
} else { \
cursor++; \
i_col++; \
} \
}
private void
do_sputc(c)
register int c;
{
if (*cursor != c) {
# ifdef ID_CHAR
if (IN_INSmode)
INSmode(OFF);
# endif
if (i_line != CapLine || i_col != CapCol)
Placur(i_line, i_col);
if (UL && (c & CHARMASK) == '_' && (*cursor & CHARMASK) != ' ')
putstr(" \b"); /* Erase so '_' looks right. */
*cursor++ = c;
jputchar(c & CHARMASK);
AbortCnt -= 1;
CapCol += 1;
} else {
cursor += 1;
}
i_col += 1;
}
#endif /* !IBMPC */
#endif /* !MAC */
void
cl_eol()
{
if (cursor > cursend)
return;
if (cursor < Curline->s_length) {
#ifdef TERMCAP
if (CE) {
Placur(i_line, i_col);
putpad(CE, 1);
clrline(cursor, Curline->s_length);
} else {
/* Ugh. The slow way for dumb terminals. */
register char *savecp = cursor;
while (cursor <= Curline->s_length)
sputc(' ');
cursor = savecp;
}
#else /* !TERMCAP */
Placur(i_line, i_col);
clr_eoln();
clrline(cursor, Curline->s_length);
#endif /* !TERMCAP */
Curline->s_length = cursor;
}
}
void
cl_scr(doit)
bool doit;
{
register int i;
register struct screenline *sp = Screen;
for (i = 0; i < LI; i++, sp++) {
clrline(sp->s_line, sp->s_length);
sp->s_length = sp->s_line;
PhysScreen[i].s_id = 0;
}
if (doit) {
#ifdef TERMCAP
putpad(CL, LI);
#else /* !TERMCAP */
clr_page();
#endif /* !TERMCAP */
CapCol = CapLine = 0;
UpdMesg = YES;
}
}
/* Write `line' at the current position of `cursor'. Stop when we
reach the end of the screen. Aborts if there is a character
waiting. */
bool
swrite(line, inversep, abortable)
register char *line;
bool inversep;
bool abortable;
{
register int n = cursend - cursor;
bool aborted = NO;
if (n > 0) {
register int c;
int col = i_col;
#ifdef MAC
# define spit(c) sputc(c)
#else /* !MAC */
#ifdef IBMPC
# define spit(c) sputc(c)
#else /* !IBMPC */
int or_byte = inversep ? 0200 : 0;
# define spit(c) { int temp = (c) | or_byte; sputc(temp); }
#endif /* !IBMPC */
#endif /* !MAC */
#ifdef MAC
sput_start(); /* Okay, because no interruption possible */
#endif /* MAC */
#ifdef IBMPC
force = inversep; /* to force a redraw of the modeline */
#endif
while ((c = *line++) != '\0') {
# define spot(c) { if (--n <= 0) break; spit(c); col += 1; }
if (abortable && AbortCnt < 0) {
AbortCnt = BufSize;
if ((InputPending = charp()) != NO) {
aborted = YES;
break;
}
}
if (c == '\t') {
int nchars;
nchars = (tabstop - (col % tabstop));
while (--nchars > 0)
spot(' ');
c = ' ';
} else if (jiscntrl(c)) {
spot('^');
c = (c == '\177') ? '?' : c + '@';
#ifdef TERMCAP
} else if (Hazeltine && c == '~') {
c = '`';
#endif
#ifdef IBMPC
} else if (c == 255) {
c = 1;
} else if (c == ' ' && inversep) {
c = 255;
#endif /* IBMPC */
}
spot(c);
# undef spot
}
if (n <= 0)
spit(((*line=='\0') && (c!='\t') && !jiscntrl(c))? c : '!');
if (cursor > Curline->s_length)
Curline->s_length = cursor;
#ifdef MAC
sput_end();
#endif /* MAC */
#ifdef IBMPC
force = NO;
#endif
# undef spit
}
return !aborted;
}
/* This is for writing a buffer line to the screen. This is to
minimize the amount of copying from one buffer to another buffer.
This gets the info directly from the disk buffers. */
bool
BufSwrite(linenum)
int linenum;
{
register int n = cursend - cursor,
col = 0,
c = -1;
register char *bp;
int StartCol = DesiredScreen[linenum].s_offset,
visspace = DesiredScreen[linenum].s_window->w_flags & W_VISSPACE;
bool aborted = NO;
bp = lcontents(DesiredScreen[linenum].s_lp);
if (*bp) {
for (;;) {
if (col >= StartCol) {
DesiredScreen[linenum].s_offset = col;
break;
}
c = *bp++ & CHARMASK;
if (c == '\0')
break;
if (c == '\t')
col += (tabstop - (col % tabstop));
else if (jiscntrl(c))
col += 2;
else
col += 1;
}
}
#ifdef MAC
sput_start(); /* Okay because we can't be interrupted */
#endif
if (c != '\0') {
while ((c = *bp++) != '\0') {
# define spot(c) { if (--n <= 0) break; sputc(c); col += 1; }
if (AbortCnt < 0) {
AbortCnt = BufSize;
if ((Input